/**
 * 
 */
package qy.jalgotrade.dataseries.resampled;

import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;

import qy.jalgotrade.utils.resamplebase.Grouper;

/**
 * @author c-geo
 *
 */
public class AggFunGrouper<T> extends Grouper<T> {

	private List<T> __values;

	private Function<List<T>, T> __aggfun;

	/**
	 * @param groupDateTime
	 */
	public AggFunGrouper(ZonedDateTime groupDateTime, Function<List<T>, T> aggfun) {

		super(groupDateTime);
		__values = new ArrayList<>();
		__aggfun = aggfun;
	}

	/* (non-Javadoc)
	 * @see qy.jalgotrade.utils.resamplebase.Grouper#addValue(java.lang.Object)
	 */
	@Override
	public void addValue(T value) {

		__values.add(value);
	}

	/* (non-Javadoc)
	 * @see qy.jalgotrade.utils.resamplebase.Grouper#getGrouped()
	 */
	@Override
	public T getGrouped() throws Exception {

		return __aggfun.apply(__values);
	}
}
